<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<script type="text/javascript">
	var dict_tree;
	$(function() {
		dict_tree = $('#dict_tree').tree({
			url:'${ctx}/sys/dict/tree',
			idFiled:'id',
			textFiled:'text',
			parentField :'pid',
			attributes : 'attributes',
			state:'state',
			lines:true,
			multiple:true,
			onlyLeafCheck:true,
			cascadeCheck: true,
			onClick : function(node) {
				$("#dict_updateFrom").form('clear');
		        var url = "${ctx}/sys/dict/getDetailById?id=" + node.id;
		        $("#dict_updateFrom").form('load', url);
			}
		});
		
		$('#dict_pid').combotree({
			 url:'${ctx}/sys/dict/tree',
			 idFiled:'id',
			 textFiled:'text',
			 parentField :'pid',
			 lines:true
		 });
	});
	
	//保存
	var dict_saveFun=function(){
		$('#dict_updateFrom').form('submit',{
			url : '${ctx}/sys/dict/update',
			success : function(result) {
				try {
					var r = $.parseJSON(result);
					if (r.success) {
						dict_tree.tree('reload'); // 刷新数据   
						$('#dict_pid').combotree('reload');
						$("#dict_updateFrom").form('clear');
					}
					$.messager.show({
						title : '温馨提示',
						msg : r.message
					});
				} catch (e) {
					$.messager.alert('温馨提示',result);
				}
			}
	  });
	};
	
	//添加同级
	var dict_addTJFun = function() {
		var pid=$("#dict_pid").combotree("getValue");
		$("#dict_updateFrom").form('clear');
		$("#dict_pid").combotree("setValue",pid);
		
	};
	
	//添加下级
	var dict_addXJFun = function() {
		var id=$("#dict_id").val();
		$("#dict_updateFrom").form('clear');
		$("#dict_pid").combotree("setValue",id);
		
	};	
	
	

	//移除
	var dict_removeFun = function() {
		var id=$("#dict_id").val();
		if(id==""){
			$.messager.alert('温馨提示',"请选择一条数据");
			return;
		}
		parent.$.messager.confirm('询问', '您确定要删除此记录？', function(r) {
			if (r) {
				$.post('${ctx}/sys/dict/delete', {
					id : id
				}, function(data) {
					try {
						if (data.success) {
							dict_tree.tree('reload'); // 刷新数据   
							$('#dict_pid').combotree('reload');
							$("#dict_updateFrom").form('clear');
						}
						$.messager.show({
							title : '温馨提示',
							msg : data.message
						});
					} catch (e) {
						$.messager.alert('温馨提示',data.message);
					}
				}, 'json');
			}
		});
	};
	
	//展开
	var res_redoFun = function() {
		var node = res_treegrid.treegrid('getSelected');
		if (node) {
			res_treegrid.treegrid('expandAll', node.id);
		} else {
			res_treegrid.treegrid('expandAll');
		}
	};
	//折叠
	var res_undoFun = function() {
		var node = res_treegrid.treegrid('getSelected');
		if (node) {
			res_treegrid.treegrid('collapseAll', node.id);
		} else {
			res_treegrid.treegrid('collapseAll');
		}
	};
	
</script>
<!-- 界面布局  -->
<div class="easyui-layout" style="width: 100%; height: 100%;" data-options="fit:true,border:false">
	<div data-options="region:'center',title:'字典信息'" style="padding: 2px; width: 300px">
		<table id="dict_tree"></table>
	</div>
	<div data-options="region:'east', split:true,title:'字典详细信息'" style="width: 800px;">
		<form id="dict_updateFrom" method="post">
			<table class="stable" cellpadding="1" cellspacing="1" style="width: 100%">
				<input id="dict_id" type="hidden" name="id" ></input>
				<tr>
					<td width="25%" class="stdlabel">字典上级</td>
					<td width="75%" class="stdinput">
					<input id="dict_pid"  name="pid" style="width:200%;" />
					</td>
				</tr>
				<tr>
					<td width="25%" class="stdlabel">字典名称</td>
					<td width="75%" class="stdinput">
						<input name="name" class="easyui-validatebox"  data-options="required:true,tipPosition:'left'" style="width:100%;" />
					</td>
				</tr>
				<tr>
					<td width="25%" class="stdlabel">字典值</td>
					<td width="75%" class="stdinput">
						<input name="value"   style="width:100%;" />
					</td>
				</tr>
				<tr>
					<td width="25%" class="stdlabel">排序号</td>
					<td width="75%" class="stdinput">
						<input name="sort" class="easyui-validatebox"  data-options="required:true,tipPosition:'left'" style="width:100%;" />
					</td>
				</tr>
				<tr>
					<td width="25%" class="stdlabel">状态</td>
					<td width="75%" class="stdinput">
						<select  name="status" data-options="required:true,tipPosition:'left'" class="easyui-combobox" style="width:100%;">
						  <option value="1">有效</option>  
						  <option value="0">无效</option>     
	  					</select>
					</td>
				</tr>
				<tr>
					<td width="25%" class="stdlabel">备注</td>
					<td width="75%" class="stdinput">
						<input name="remarks"  style="width:100%;" />
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<div style="margin: 0px; padding-top: 5px;" align="center">
						<a onclick="dict_addTJFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-add'">新增同级</a>
						<a onclick="dict_addXJFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-add'">新增子级</a>
						<a onclick="dict_saveFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-save'">保存</a>	
						<a onclick="dict_removeFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'">删除</a>
						</div>
					</td>
				</tr>
			</table>
		</form>
	</div>
</div>